<%@ page import="com.example.ordersystem.domain.Comment" %><%--
  Created by IntelliJ IDEA.
  User: 檬zhu
  Date: 2021/12/13
  Time: 16:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
    <style type="text/css">
        .divX {
            z-index: 200;
            -moz-border-radius: 20px;
            -webkit-border-radius: 20px;
            line-height: 10px;
            text-align: center;
            font-weight: bold;
            cursor: pointer;
            font-size: 10px;
            display: none;
        }
    </style>
</head>
<%
    String orderNum = (String) request.getAttribute("orderNum");
%>
<body>
<form action="${pageContext.request.contextPath}/customer/addComment" id="form" class="layui-form layui-form-pane"
      style="width: 60%;margin-left: 10%" enctype="multipart/form-data" method="post">

    <input type="hidden" name="orderNum" value="<%=orderNum%>">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>订单打分</legend>
    </fieldset>
    <div id="test2"></div>
    <input type="hidden" name="number" id="num">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>好评理由</legend>
    </fieldset>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left: 0">
            <input type="checkbox" name="label" value="<%=Comment.WORTHY%>" title="<%=Comment.WORTHY%>"
                   checked="checked">
            <input type="checkbox" name="label" value="<%=Comment.EFFICIENT%>" title="<%=Comment.EFFICIENT%>"
                   checked="checked">
            <input type="checkbox" name="label" value="<%=Comment.SINCERE%>" title="<%=Comment.SINCERE%>"
                   checked="checked">
            <input type="checkbox" name="label" value="<%=Comment.GENEROUS%>" title="<%=Comment.GENEROUS%>"
                   checked="checked">
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>评价内容</legend>
    </fieldset>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">说点什么</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="content"></textarea>
        </div>
    </div>


    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>配图</legend>
    </fieldset>

    <input type="file" name="file" accept="image/*" id="file_input" onchange="addFile(this);" style="display:none"/>
    <div style="position: relative;">
        <img id="file_img" src="${pageContext.request.contextPath}/resources/images/upload.png" width="120"
             onclick="file_input.click();"
             height="100"/>
    </div>
    <div class="divX" id="img_zindex_div_1" onclick="del()">
        <img src="${pageContext.request.contextPath}/resources/images/delete.png" width="16" height="16"/>
    </div>
    <input type="hidden" name="choose" id="choose" value="no">

    <script src="${pageContext.request.contextPath}/resources/js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">

        function addFile(ths) {
            var objUrl = getObjectURL(ths.files[0]);
            var left = $('#file_img').position().left;
            var top = $('#file_img').position().top;
            $('#img_zindex_div_1').css({position: "absolute", display: "block"});
            $('#file_img').attr("src", objUrl);
            $('#file_input').attr("value", objUrl);
            document.getElementById("choose").value = 'yes';
        }

        function del() {
            if (confirm("删除?")) {
                $("#file_img").attr("src", "/resources/images/upload.png");
                $('#img_zindex_div_1').css({position: "relative", display: "none"});
                $('#file_input').removeAttribute("value")
                document.getElementById("choose").value = 'no';
            }
        }

        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL != undefined) { // basic
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }
    </script>

    <div class="layui-form-item" style="margin-left: 25%">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">发布评价</button>
        </div>
    </div>

</form>
<script src="${pageContext.request.contextPath}/resources/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['rate'], function () {
        const rate = layui.rate;
        //显示文字
        rate.render({
                elem: '#test2'
                , value: 2 //初始值
                , text: true //开启文本
                , setText: function (value) {
                    console.log(value)
                    document.getElementById("num").value = value
                }
            }
        );
    });
</script>

<script>
    //Demo
    layui.use('form', function () {
        const form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
</script>
</body>
</html>
